﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Controllers.Demain;

namespace WebApplication1.Controllers
{
    public class DbInit
    {
        public static void Init()
        {
            using(var db = new AdminDb())
            {
                db.Database.EnsureCreated();

                var Emplit = db.Students.Any();

                if (!Emplit)
                {
                    var Class1 = new Clbum
                    {
                        ClassName = "计应4班",
                        StudentNun = 38
                    };

                    db.Clbums.Add(Class1);
                    db.SaveChanges();


                    db.AddRange(new Student[]
                    {
                    new Student
                    {
                        StudentName="华铭隔壁",
                        Age=18,
                        Sex="男",
                        ClassId=Class1.Id
                    },
                    new Student
                    {
                        StudentName="许嘉隔壁",
                        Age=19,
                        Sex="男",
                        ClassId=Class1.Id
                    }
                    });
                    db.SaveChanges();

                }
            }
        }
    }
}
